<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Login
 *
 * @author alan
 */
$path=$_SERVER["DOCUMENT_ROOT"]."/Clase/php/FORO/clases/";
include_once ($path."BaseDatos.php");

class Login {
    //put your code here
    private $user;
    private $_grup;
    private $_passwd;
    private $_conect;
    private static $_urlOK="localhost/index.php";
    private static $_urlOFF="localhost/unlogin.php";
    
    public function __construct(){
    }
    
    public function login(){
    	$conect = new BaseDatos();
        $consulta="SELECT passwd, id_grup FROM usuaris WHERE (email='".$_REQUEST["email"]."') AND valid='1'";
        $e=$conect->prepare($consulta);
        $e->execute();
        if ($e==0) header("Location: index.php?e=101");
        while ($r=$e->fetchALL(PDO::FETCH_ASSOC)){
        	if($_REQUEST["passwd"]==$r["passwd"]){
           		$_SESSION["USUSARI"]=$_REQUEST["email"];
           		$_SESSION["grup"]=$r["id_grup"];
            	return 0;
        	} else return 1;
    	}
    }
    
    public function unLogin(){
        unset($_SESSION["usuari"]);
        unset($_SESSION["id_grup"]);
        header("Location: index.php");
        return 0;
    }
  
    public function getUrlOn(){return $this->_urlOK;}
    public function getUrlOff(){ return $this->_urlOFF;}
}

?>
